import ImportData from "./import/index.vue";
export default {
  components: {
    ImportData,
  },
  data() {
    return {
      searchItem: {
        searchKey: "",
      },
      add: false,
      styles: {
        height: "calc(100% - 55px)",
        overflow: "auto",
        paddingBottom: "53px",
        position: "static",
      },
      formData: {},
      success: false,
      columns: [
        {
          title: "书名",
          key: "name",
          fixed: "left",
          width: 150,
        },
        {
          title: "编者",
          key: "author",
        },
        {
          title: "绘画",
          key: "draw",
        },
        {
          title: "封面",
          key: "cover",
        },
        {
          title: "出版社",
          key: "press",
        },
        {
          title: "出版年份",
          key: "pubYear",
        },
        {
          title: "出版月份",
          key: "pubMonth",
        },
        {
          title: "印数",
          key: "count",
        },
        {
          title: "定价",
          key: "price",
        },
        {
          title: "页数",
          key: "page",
        },
        {
          title: "开本",
          key: "bookSize",
        },
        {
          title: "版次信息",
          key: "edition",
        },
      ],
      count: 0,
      total:0,
      page: 1,
      pageSize: 10,
      datalist: [],
      showImport: false,
    };
  },
  computed: {
    user() {
      return this.$store.state.user;
    },
  },
  methods: {
    menuClick(name) {
      if (name == "loginOut") {
        var that = this;
        this.$Modal.confirm({
          title: "退出",
          content: "确认退出当前账户么?",
          onOk: function () {
            var VIRTUAL_PATH = process.env.VUE_APP_VIRTUAL_PATH;
            that.$router.push(`${VIRTUAL_PATH}/login?isExit=true`);
          },
        });
      }
    },
    saveInfo() {
      this.$axios({
        url: "/api/book",
        method: "PUT",
        data: this.formData,
      }).then((res) => {
        if (res.code == 200) {
          this.success = true;
          this.formData = {};
          this.getData();
        } else {
          this.$Message.error(res.msg);
        }
      });
    },
    pageChange(page) {
      this.page = page;
      this.getData();
    },
    pageSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.getData();
    },
    getData() {
      this.$axios({
        url: `/api/book/list`,
        method: "POST",
        data: {
          page: this.page,
          pageSize: this.pageSize,
          searchKey: this.searchItem.searchKey,
        },
      }).then((res) => {
        if (res.code == 200) {
          this.datalist = res.data.list;
          this.count = res.data.count;
          this.total = res.data.total;
        }
      });
    },
  },
  created() {
    this.getData();
  },
};
